package com.tencent.wxpay.demo.service.impl;

import com.tencent.wxpay.WXPay;
import com.tencent.wxpay.demo.listener.ResultListener;
import com.tencent.wxpay.demo.service.OrderQueryService;
import com.tencent.wxpay.demo.util.TestUtil;
import com.tencent.wxpay.protocol.request.OrderQueryReqData;
import com.tencent.wxpay.protocol.response.OrderQueryResData;
import org.springframework.stereotype.Service;

@Service
public class OrderQueryServiceImpl implements OrderQueryService {

    @Override
    public OrderQueryResData doOrderQuery(String outTradeNo) {
        try{
            OrderQueryReqData orderQueryReqData = new OrderQueryReqData(null,outTradeNo);
            OrderQueryResData orderQueryResData = WXPay.doOrderQueryBusiness(orderQueryReqData, new ResultListener<OrderQueryResData>());
            return orderQueryResData;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    public static void main(String[] args) {
        if(TestUtil.init()){
            try{
                OrderQueryService orderQueryService = new OrderQueryServiceImpl();
                OrderQueryResData orderQueryResData = orderQueryService.doOrderQuery("20161014105955");
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
